<?php
/**
 * 品质标签模型
 * (model)
 */
namespace App\Models\Quality;

use Illuminate\Database\Eloquent\Model;
class QDictTag extends Model
{
    protected $table = 'quality_dict_tag';

    protected $guarded = [];

    public static $_type = [
        1 => '尺码问题',
        2 => '做工问题',
        3 => '设计问题',
        4 => '主观问题',
        5 => '其它问题',
    ];

    public static function options($where = [])
    {
        $query = $where ? self::query()->where(formatCondition($where)) : self::query();
        return $query->pluck('tag','id');
    }

    public static function getTagId($tag): array
    {
        if(!$tag)return [];
        $tagId = [];
        foreach ($tag as $item){
            $tagId = array_merge($tagId,$item);
        }
        return $tagId;
    }

    public static function getTag($tag): array
    {
        $tagId = self::getTagId($tag);
        return self::query()->whereIn('id',$tagId)->pluck('tag')->toArray();
    }

    public static function getTagOption($tag): array
    {
        $tagId = self::getTagId($tag);
        return self::query()->whereIn('id',$tagId)->pluck('tag','id')->toArray();
    }

    public static function getData($re){
        foreach ($re as $row){
            $temp = [
                self::$_type[$row->type],
                $row->tag,
            ];
            yield $temp;
        }
    }
}
